package com.demo.controller;

import com.demo.entity.Partner;
import com.demo.model.JsonMessage;
import com.demo.security.AuthUserDetail;
import com.demo.service.PartnerFindService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

/**
 * @author 秋水浮萍
 * @version 1.0.0
 * @ClassName PartnerFindController.java
 * @Description TODO
 * @createTime 2021年03月04日 22:36:00
 */
@RestController
@Api(value = "伙伴列表接口")
@RequestMapping("/user/partnerFind")
public class PartnerFindController {

    @Autowired
    private PartnerFindService service;

    @ApiOperation(value = "资产伙伴信息")
    @PostMapping("assetInf")
    public JsonMessage assetInf(
            Authentication authentication,
            String company, Integer partnerType,
            String belong, @RequestParam(value = "cities[]", required = false, defaultValue = "") String[] cities, String orgType,
            String orgRemark, String typeId,
            @RequestParam(defaultValue = "1") int pageIndex,
            @RequestParam(defaultValue = "10") int pageSize) {
        AuthUserDetail detail = (AuthUserDetail) authentication.getDetails();
        JsonMessage message = new JsonMessage();
        PageInfo<Partner> pageInfo = service.findAssetInf(detail.getUserId(), company, partnerType, belong, cities, orgType, orgRemark, typeId, pageIndex, pageSize);
        message.setData(pageInfo);
        return message;
    }

    @ApiOperation(value = "资金伙伴信息")
    @PostMapping("fundInfo")
    public JsonMessage fundInfo(
            Authentication authentication,
            String company, Integer partnerType, String orgType, String orgRemark,
            String currency, String incomeType,
            String struct, Integer scaleMin, Integer scaleMax, String deadline,
            @RequestParam(value = "cities[]", required = false, defaultValue = "") String[] cities, String typeId, String typeName, Integer incomeRate,
            @RequestParam(defaultValue = "1") int pageIndex,
            @RequestParam(defaultValue = "10") int pageSize) {
        AuthUserDetail detail = (AuthUserDetail) authentication.getDetails();
        JsonMessage message = new JsonMessage();
        PageInfo<Partner> pageInfo = service.findFundInfo(detail.getUserId(), company, partnerType, orgType, orgRemark, currency, incomeType, struct, scaleMin, scaleMax, deadline, cities, typeId, typeName, incomeRate, pageIndex, pageSize);
        message.setData(pageInfo);
        return message;
    }

    @ApiOperation(value = "退出伙伴信息")
    @PostMapping("exitInfo")
    public JsonMessage exitInfo(
            Authentication authentication,
            String company, Integer partnerType, String orgType, String orgRemark,
            String usage,
            String typeId, String typeName, @RequestParam(value = "cities[]", required = false, defaultValue = "") String[] cities,
            Integer abilityMin, Integer abilityMax,
            @RequestParam(defaultValue = "1") int pageIndex,
            @RequestParam(defaultValue = "10") int pageSize) {
        AuthUserDetail detail = (AuthUserDetail) authentication.getDetails();
        JsonMessage message = new JsonMessage();
        PageInfo<Partner> pageInfo = service.findExitInfo(detail.getUserId(), company, partnerType, orgType, orgRemark, usage, typeId, typeName, cities, abilityMin, abilityMax, pageIndex, pageSize);
        message.setData(pageInfo);
        return message;
    }

    @ApiOperation(value = "司法伙伴信息")
    @PostMapping("justiceInfo")
    public JsonMessage justiceInfo(
            Authentication authentication,
            Integer partnerType, String company,
            String post, @RequestParam(value = "cities[]", required = false, defaultValue = "") String[] cities,
            @RequestParam(defaultValue = "1") int pageIndex,
            @RequestParam(defaultValue = "10") int pageSize) {
        AuthUserDetail detail = (AuthUserDetail) authentication.getDetails();
        JsonMessage message = new JsonMessage();
        PageInfo<Partner> pageInfo = service.findJusticeInfo(detail.getUserId(), partnerType, company, post, cities, pageIndex, pageSize);
        message.setData(pageInfo);
        return message;
    }

    @ApiOperation(value = "同业伙伴信息")
    @PostMapping("peerInfo")
    public JsonMessage peerInfo(
            Authentication authentication,
            String company, Integer partnerType, String orgType,
            String bizListId, String coopListId
            , @RequestParam(value = "cities[]", required = false, defaultValue = "") String[] cities,
            @RequestParam(defaultValue = "1") int pageIndex,
            @RequestParam(defaultValue = "10") int pageSize) {
        AuthUserDetail detail = (AuthUserDetail) authentication.getDetails();
        JsonMessage message = new JsonMessage();
        PageInfo<Partner> pageInfo = service.findPeerInfo(detail.getUserId(), company, partnerType, orgType, bizListId, coopListId, cities, pageIndex, pageSize);
        message.setData(pageInfo);
        return message;
    }

    @ApiOperation(value = "政府伙伴信息")
    @PostMapping("orgInfo")
    public JsonMessage orgInfo(
            Authentication authentication,
            Integer partnerType, String company,
            String post, @RequestParam(value = "cities[]", required = false, defaultValue = "") String[] cities,
            @RequestParam(defaultValue = "1") int pageIndex,
            @RequestParam(defaultValue = "10") int pageSize) {
        AuthUserDetail detail = (AuthUserDetail) authentication.getDetails();
        JsonMessage message = new JsonMessage();
        PageInfo<Partner> pageInfo = service.findOrgInfo(detail.getUserId(), partnerType, company, post, cities, pageIndex, pageSize);
        message.setData(pageInfo);
        return message;
    }
}
